package a1_3;

import java.util.ArrayList;
import java.util.List;

/**
 * 学院类（对应实验A1-3的School），关联系部和学生
 */
public class School {
    private String schoolId;
    private String schoolName;

    // 关联：包含1~多个系部（List存储，控制数量≥1）
    private List<Department> departments = new ArrayList<>();

    // 关联：拥有0~多个学生（List存储）
    private List<Student> students = new ArrayList<>();

    public School() {}

    public School(String schoolId, String schoolName) {
        this.schoolId = schoolId;
        this.schoolName = schoolName;
    }

    // 添加系部（至少1个）
    public void addDepartment(Department department) {
        departments.add(department);
        department.setSchool(this); // 双向关联，同步系部的学院
    }

    // 添加学生（0~多个）
    public void addStudent(Student student) {
        students.add(student);
        student.setSchool(this); // 双向关联，同步学生的学院
    }

    // 校验约束：至少有1个系部
    public boolean isValid() {
        return !departments.isEmpty();
    }

    // Getter/Setter
    public String getSchoolId() {
        return schoolId;
    }

    public void setSchoolId(String schoolId) {
        this.schoolId = schoolId;
    }

    public String getSchoolName() {
        return schoolName;
    }

    public void setSchoolName(String schoolName) {
        this.schoolName = schoolName;
    }

    public List<Department> getDepartments() {
        return new ArrayList<>(departments);
    }

    public List<Student> getStudents() {
        return new ArrayList<>(students);
    }
}
